home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / preccx / prccx240.lha / ccdata.c < prev    next >
C/C++ Source or Header  |  1993-04-18  |  3KB  |  113 lines

  1.  
  2. /*
  3.  * parser suite - and / or / nothing / something  parsers
  4.  *
  5.  * parser = [token] -> ([token],status)
  6.  *
  7.  * implemented as sideeffecting on [token], returns status.
  8.  */
  9.  
  10. #include "cc.h"
  11. #include <stdlib.h>
  12.  
  13. #ifdef __MSDOS__
  14. #include <alloc.h>
  15. #define INDOS 1
  16. #else
  17. #define INDOS 0
  18. #endif
  19.  
  20. VOID  p_creat_data ()
  21.  
  22. /* we think one of the stacks at least is NULL, and we try and alloc it */
  23. {
  24.     long            bytesfree;
  25.  
  26.     bytesfree = p_memleft ();
  27.  
  28.     /* but which stack is it? */
  29.  
  30.     /* compilation warnings for maybe losing digits from the args of
  31.      * p_calloc should always be ignored. The numbers can't be that big! */
  32.  
  33.     if (buffer == NULL)
  34.     buffer = (TOKEN *) p_calloc (precc_data.readbuffersize, sizeof (TOKEN));
  35.  
  36.     if (lvbuff == NULL)
  37.     lvbuff = (VALUE *) p_calloc (precc_data.readbuffersize, sizeof (VALUE));
  38.  
  39.     if (program == NULL)
  40.     program = (INSTRUCTION *) p_calloc (precc_data.maxprogramsize,
  41.                                                     sizeof (INSTRUCTION));
  42.  
  43.     if (stack == NULL) {
  44.     stack = (STACKVALUE *) p_calloc (precc_data.stacksize, sizeof (STACKVALUE));
  45.     value = stack;        /* top of evaluation stack */
  46.     }
  47.  
  48.     if (fstack == NULL) {
  49.     fstack = (FRAME *) p_calloc (precc_data.contextstacksize, sizeof (FRAME));
  50.     fptr = fstack;
  51.     }
  52.  
  53.     if (buffer == NULL || lvbuff == NULL || program == NULL || stack == NULL || fstack == NULL) {
  54.     fprintf (stderr,
  55.      "error; not enough memory (%lu) for internal stacks\n", bytesfree);
  56.     exit (1);
  57.     }
  58.     return;
  59. }
  60.  
  61. VOID            p_destr_data ()
  62. {
  63.     if (buffer != NULL)
  64.     p_free (buffer);
  65.     if (lvbuff != NULL)
  66.     p_free (lvbuff);
  67.     if (program != NULL)
  68.     p_free (program);
  69.     if (stack != NULL)
  70.     p_free (stack);
  71.     if (fstack != NULL)
  72.     p_free (fstack);
  73.     return;
  74. }
  75.  
  76. /* globals */
  77.  
  78. int             p_argc;
  79. char          **p_argv;
  80. TOKEN          *buffer;        /* where the pstr points to */
  81. TOKEN          *yybuffer;      /* internal name for buffer */
  82. VALUE          *lvbuff;        /* the parallel stack of yylvals */
  83.  
  84. INSTRUCTION    *program;
  85. STACKVALUE     *stack;        /* the evaluation stack - either values or
  86.                                * tokens */
  87. STACKVALUE     *value;
  88. FRAME           p_frame;      /* all one needs to know for a rewind */
  89. FRAME          *fstack;
  90. FRAME          *fptr;
  91.  
  92.  /* this IS a frame */
  93.  
  94. TOKEN          *pstr;         /* parsed stream */
  95. int             pc;           /* program counter - counts up from 0 */
  96. int             passcount;    /* input lines counted here */
  97.  
  98.  /* end of frame */
  99.  
  100. INSTRUCTION     instr;        /* instruction cache */
  101. TOKEN          *maxp;        /* maximum number parsed so far */
  102. int             call_mode = 0;    /* flag for call convention. 1 = pascal
  103.                               * (manual), 0 = C (auto) */
  104. jmp_buf         jmpb;        /* environment */
  105. int             optimize = 0;    /* flag for flying program optimization */
  106. int             msdos = INDOS;    /* 1 if we're in MSDOS */
  107. PARSER         *p_entry;    /* entry point set by p_run & btck_error */
  108. int             p_enargs;
  109. PARAM           p_eargv[MAXARGS];
  110.  
  111. PRECC_DATA      precc_data;
  112.  
  113.